import type { PropsWithChildren } from 'react';

import '@ant-design/v5-patch-for-react-19';
import { App } from 'antd';

// ContextHolder 组件：用于将 Ant Design 的全局 message、modal、notification 挂载到 window 对象，方便全局调用
function ContextHolder() {
  const { message, modal, notification } = App.useApp();
  window.$message = message;
  window.$modal = modal;
  window.$notification = notification;
  return null;
}

// AppProvider 组件：为子组件提供 Ant Design App 上下文环境，确保全局弹窗、消息等功能可用
const AppProvider = ({ children }: PropsWithChildren) => {
  return (
    <App className="h-full">
      <ContextHolder />
      {children}
    </App>
  );
};

export default AppProvider;
